package com.example.yan.excel_split.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class demo3 {




        public static void main(String[] args) {
            List<Map> list1 = new ArrayList<>();
            for (int i = 0; i <10 ; i++) {
                Map map = new HashMap();
                map.put("终端号",1000+i);
                if (i>6){
                    map.put("发卡行","中行");
                }else if(i<3){
                    map.put("发卡行","农商");
                }else {
                    map.put("发卡行","建行");
                }
                map.put("交易金额",10D+i);
                map.put("交易类型","消费");
                list1.add(map);
            }
            System.out.println(list1.toString());
            Map<Object, List<Map>> groupBy = list1.stream().collect(Collectors.groupingBy(map -> {return map.get(("发卡行"));}));
            System.out.println(groupBy);
            List list3 = new ArrayList();
            groupBy.keySet().forEach(o -> {
                List<Map> list2 = groupBy.get(o);
                double q = 0D;
                for (Map map : list2) {
                    q = q + (double)map.get("交易金额");
                    list3.add(map);
                }
                Map map1 = new HashMap();
                map1.put("发卡行","终端小计算(不含退货)");
                map1.put("交易金额",q);
                list2.add(map1);
                System.out.println(list2);
                list3.add(map1);
            });
            System.out.println(list3);
        }




}